package org.htmlparser.lexer;

import java.io.Serializable;
import org.htmlparser.util.sort.Ordered;

public class Cursor
  implements Serializable, Ordered, Cloneable
{
  protected Page mPage;
  protected int mPosition;

  public Cursor(Page paramPage, int paramInt)
  {
    this.mPage = paramPage;
    this.mPosition = paramInt;
  }

  public void advance()
  {
    this.mPosition = (1 + this.mPosition);
  }

  public int compare(Object paramObject)
  {
    Cursor localCursor = (Cursor)paramObject;
    return (getPosition() - localCursor.getPosition());
  }

  public Cursor dup()
  {
    Cursor localCursor1;
    Cursor localCursor2;
    try
    {
      localCursor2 = (Cursor)super.clone();
      localCursor1 = localCursor2;
      return localCursor1;
    }
    catch (CloneNotSupportedException localCloneNotSupportedException)
    {
      localCursor1 = new Cursor(getPage(), getPosition());
    }
  }

  public Page getPage()
  {
    return this.mPage;
  }

  public int getPosition()
  {
    return this.mPosition;
  }

  public void retreat()
  {
    this.mPosition -= 1;
    if (this.mPosition < 0)
      this.mPosition = 0;
  }

  public void setPosition(int paramInt)
  {
    this.mPosition = paramInt;
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer(30);
    localStringBuffer.append(getPosition());
    localStringBuffer.append("[");
    if (this.mPage != null)
    {
      localStringBuffer.append(this.mPage.row(this));
      localStringBuffer.append(",");
      if (this.mPage == null)
        break label95;
      localStringBuffer.append(this.mPage.column(this));
    }
    while (true)
    {
      while (true)
      {
        localStringBuffer.append("]");
        return localStringBuffer.toString();
        localStringBuffer.append("?");
      }
      label95: localStringBuffer.append("?");
    }
  }
}